import Vue from 'vue'
import Router from 'vue-router'
import routes from './module.router'
import Util from '@plugins/util'
import Wx from '@plugins/wx'
import Storage from '@plugins/storage'
import API from '@api/index'

const router = new Router({
    routes
})

router.beforeEach((to, from, next) => {
    document.title = to.meta.title
    let mlUser = Storage.get("ML_USER_INFO");
    let whiteList = ["/login","/service","/privacy"]
    if (mlUser && mlUser.token) {
        next()
    } else {
        console.log('-------------------',to.path);
        if (whiteList.includes(to.path)) {
            next()
            
        } else {
            window.location.replace(API.wechatRedirect+'?redirect_uri='+encodeURIComponent('https://healthc.mirror-networks.com/h5/dietitian/#/login?redirect='+ to.fullPath))
        }
    }

    
})

router.afterEach((to, from) => {
    if(!Util.ua.isWx()) return;
    if(Util.ua.isAndroid) Wx.hideShare()
    // let conf = {
    //     title: 'xxxx', // 分享标题
    //     desc: 'xxxxxxxx', // 分享描述
    //     link: origin + pathname + '#/jump?channel='+this.union_channel+'&to=healthSurvey',
    //     imgUrl: '' // 分享图标
    // }
    // switch (to) {
    //     case 'xxxx':
    //         conf.xxx = 'xxxx'
    //         break;
    //     default:
    //         break;
    // }
    // if(!conf.imgUrl) Wx.setShare(conf)
})

export default router